<?php

/**
 * @author 	Samuel Carlier
 * @package	P3Base_Mailer
 */
class P3Base_Mailer_Envelope {

	/**
	 * @var P3Base_Mailer_Addresses
	 */
	private $_addresses;

	/**
	 * @var P3Base_Mailer_Message
	 */
	private $_message;

	/**
	 * @var P3Base_Mailer_Files
	 */
	private $_files;
	
	/**
	 * @var P3Base_Mailer_Headers
	 */
	private $_headers;

	/**
	 * constructor
	 */
	public function __construct() {
		$this->_message   = new P3Base_Mailer_Message;
		$this->_files	  = new P3Base_Mailer_Files;
		$this->_addresses = new P3Base_Mailer_Addresses;
		$this->_headers	  = new P3Base_Mailer_Headers;
	}

	/**
	 * @param string $email
	 * @param stirng $name
	 */
	public function setFrom($email, $name=null) {
		$this->_addresses->add('from', $name, $email);
	}

	/**
	 * @param string $email
	 * @param stirng $name
	 */
	public function setReturnPath($email, $name=null) {
		$this->_addresses->add('return_path', $name, $email);
	}
	
	/**
	 * @param string $email
	 * @param stirng $name
	 */
	public function setReturnReciept($email, $name=null) {
		$this->_addresses->add('receipt_to', $name, $email);
	}
	
	/**
	 * @param string $email
	 * @param stirng $name
	 */
	public function setReplyTo($email, $name=null) {
		$this->_addresses->add('replay_to', $name, $email);
	}
	
	/**
	 * @param string $email
	 * @param stirng $name
	 */
	public function addTo($email, $name=null) {
		$this->_addresses->add('to', $name, $email);
	}

	/**
	 * @param string $email
	 * @param stirng $name
	 */
	public function addCc($email, $name=null) {
		$this->_addresses->add('cc', $name, $email);
	}

	/**
	 * @param string $email
	 * @param stirng $name
	 */
	public function addBcc($email, $name=null) {
		$this->_addresses->add('bcc', $name, $email);
	}

	/**
	 * @param string $name
	 * @param stirng $value
	 */
	public function addHeader($name, $value) {
		$this->_headers->add($name, $value);
	}

	/**
	 * Clear Email Addresses
	 *
	 * @param string $type can be "to, cc, bcc, from, replay_to, receipt_to or return_path"
	 */
	public function clearEmailAddresses($type=null) {
		$this->_addresses->clear($type);
	}
	
	/**
	 * @param string $subject
	 */
	public function setSubject($subject) {
		$this->_message->setSubject($subject);
	}

	/**
	 * @param string $message
	 * @param string $encoding
	 */
	public function setTextMessage($message, $encoding=P3Base_Mailer_Message::ENCODING_8BIT) {
		$this->_message->setText(new P3Base_Mailer_MessagePart($message, $encoding));
	}

	/**
	 * @param string $message
	 * @param string $encoding
	 */
	public function setHTMLMessage($message, $encoding=P3Base_Mailer_Message::ENCODING_8BIT) {
		$this->_message->setHTML(new P3Base_Mailer_MessagePart($message, $encoding));
	}

	/**
	 * @param string $encoding
	 */
	public function setTransferEncoding($encoding) {
		$this->_message->setEncoding($encoding);
	}

	/**
	 * @param string $charset
	 */
	public function setCharset($charset) {
		$this->_message->setCharset($charset);
	}

	/**
	 * @param string $file_path
	 * @param string $newname optional
	 * @param string $mime_type
	 */
	public function addFile($file_path, $newname='', $mime_type='application/octet-stream') {
		$this->_files->add($file_path, $newname, $mime_type);
	}

	/**
	 * @return P3Base_Mailer_Files
	 */
	public function getFiles() {
		return $this->_files;
	}
	
	/**
	 * @return P3Base_Mailer_Headers
	 */
	public function getHeaders() {
		return $this->_headers;
	}
	
	/**
	 * @return P3Base_Mailer_Message
	 */
	public function getMessage() {
		return $this->_message;
	}
	
	/**
	 * @return P3Base_Mailer_Addresses
	 */
	public function getAddresses() {
		return $this->_addresses;
	}
	
	/**
	 * Clear all files
	 */
	public function clearFiles() {
		$this->_files->clear();
	}
}

?>